<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单流水号" prop="serialNo">
        <el-input
          v-model="queryParams.serialNo"
          placeholder="请输入订单流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="钱包账户号" prop="walletNo">
        <el-input
          v-model="queryParams.walletNo"
          placeholder="请输入钱包账户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户号" prop="custNo">
        <el-input
          v-model="queryParams.custNo"
          placeholder="请输入客户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable size="small">
          <el-option
            v-for="dict in orderTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="申请金额" prop="applyAmount">-->
<!--        <el-input-->
<!--          v-model="queryParams.applyAmount"-->
<!--          placeholder="请输入申请金额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订单金额" prop="amount">-->
<!--        <el-input-->
<!--          v-model="queryParams.amount"-->
<!--          placeholder="请输入订单金额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订单服务费" prop="serviceFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.serviceFee"-->
<!--          placeholder="请输入订单服务费"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="钱包类型" prop="walletType">
        <el-select v-model="queryParams.walletType" placeholder="请选择钱包类型" clearable size="small">
          <el-option
            v-for="dict in walletTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="银行编码" prop="bankCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.bankCode"-->
<!--          placeholder="请输入银行编码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="银行账户" prop="bankAccount">
        <el-input
          v-model="queryParams.bankAccount"
          placeholder="请输入银行账户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="From" prop="fromWhere">-->
<!--        <el-input-->
<!--          v-model="queryParams.fromWhere"-->
<!--          placeholder="请输入From"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="To" prop="toDest">-->
<!--        <el-input-->
<!--          v-model="queryParams.toDest"-->
<!--          placeholder="请输入To"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="批次流水号" prop="batchSerialNo">
        <el-input
          v-model="queryParams.batchSerialNo"
          placeholder="请输入批次流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关联借据" prop="loanSerialNo">
        <el-input
          v-model="queryParams.loanSerialNo"
          placeholder="请输入关联借据"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable size="small">
          <el-option
            v-for="dict in orderStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="服务费率" prop="serviceRate">-->
<!--        <el-input-->
<!--          v-model="queryParams.serviceRate"-->
<!--          placeholder="请输入服务费率"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="余额最低提现金额" prop="minWithdrawBalance">-->
<!--        <el-input-->
<!--          v-model="queryParams.minWithdrawBalance"-->
<!--          placeholder="请输入余额最低提现金额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="奖励金最低提现金额" prop="minWithdrawBonus">-->
<!--        <el-input-->
<!--          v-model="queryParams.minWithdrawBonus"-->
<!--          placeholder="请输入奖励金最低提现金额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="create date">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="start time"
          end-placeholder="End time"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wallet:wallet_order:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wallet:wallet_order:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wallet:wallet_order:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wallet:wallet_order:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wallet_orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="ID" align="center" prop="id"/>
      <el-table-column label="订单流水号" align="center" prop="serialNo" width="280"/>
      <el-table-column label="钱包账户号" align="center" prop="walletNo" width="260"/>
      <el-table-column label="客户号" align="center" prop="custNo" width="200"/>
      <el-table-column label="订单类型" align="center" prop="orderType" width="140" :formatter="orderTypeFormat"/>
      <el-table-column label="申请金额" align="center" prop="applyAmount" width="120"/>
      <el-table-column label="订单金额" align="center" prop="amount" width="120"/>
      <el-table-column label="订单服务费" align="center" prop="serviceFee" width="120"/>
      <el-table-column label="钱包类型" align="center" prop="walletType" width="120" :formatter="walletTypeFormat"/>
      <el-table-column label="银行编码" align="center" prop="bankCode" width="120"/>
      <el-table-column label="银行账户" align="center" prop="bankAccount" width="180"/>
      <el-table-column label="From" align="center" prop="fromWhere" width="260"/>
      <el-table-column label="To" align="center" prop="toDest" width="260"/>
      <el-table-column label="批次流水号" align="center" prop="batchSerialNo" width="260"/>
      <el-table-column label="关联借据" align="center" prop="loanSerialNo" width="240"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus" width="120" :formatter="orderStatusFormat"/>
      <el-table-column label="服务费率" align="center" prop="serviceRate" width="120"/>
      <el-table-column label="余额最低提现金额" align="center" prop="minWithdrawBalance" width="160"/>
      <el-table-column label="奖励金最低提现金额" align="center" prop="minWithdrawBonus" width="160"/>
      <el-table-column label="状态" align="center" prop="state" :formatter="stateFormat"/>
      <el-table-column label="备注" align="center" prop="remark" width="200"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="140">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wallet:wallet_order:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wallet:wallet_order:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改钱包订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单流水号" prop="serialNo">
          <el-input v-model="form.serialNo" placeholder="请输入订单流水号"/>
        </el-form-item>
        <el-form-item label="钱包账户号" prop="walletNo">
          <el-input v-model="form.walletNo" placeholder="请输入钱包账户号"/>
        </el-form-item>
        <el-form-item label="客户号" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入客户号"/>
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="form.orderType" placeholder="请选择订单类型">
            <el-option
              v-for="dict in orderTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请金额" prop="applyAmount">
          <el-input v-model="form.applyAmount" placeholder="请输入申请金额"/>
        </el-form-item>
        <el-form-item label="订单金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入订单金额"/>
        </el-form-item>
        <el-form-item label="订单服务费" prop="serviceFee">
          <el-input v-model="form.serviceFee" placeholder="请输入订单服务费"/>
        </el-form-item>
        <el-form-item label="钱包类型" prop="walletType">
          <el-select v-model="form.walletType" placeholder="请选择钱包类型">
            <el-option
              v-for="dict in walletTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="银行编码" prop="bankCode">
          <el-input v-model="form.bankCode" placeholder="请输入银行编码"/>
        </el-form-item>
        <el-form-item label="银行账户" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入银行账户"/>
        </el-form-item>
        <el-form-item label="From" prop="fromWhere">
          <el-input v-model="form.fromWhere" placeholder="请输入From"/>
        </el-form-item>
        <el-form-item label="To" prop="toDest">
          <el-input v-model="form.toDest" placeholder="请输入To"/>
        </el-form-item>
        <el-form-item label="批次流水号" prop="batchSerialNo">
          <el-input v-model="form.batchSerialNo" placeholder="请输入批次流水号"/>
        </el-form-item>
        <el-form-item label="关联借据" prop="loanSerialNo">
          <el-input v-model="form.loanSerialNo" placeholder="请输入关联借据"/>
        </el-form-item>
        <el-form-item label="订单状态" prop="orderStatus">
          <el-select v-model="form.orderStatus" placeholder="请选择订单状态">
            <el-option
              v-for="dict in orderStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服务费率" prop="serviceRate">
          <el-input v-model="form.serviceRate" placeholder="请输入服务费率"/>
        </el-form-item>
        <el-form-item label="余额最低提现金额" prop="minWithdrawBalance">
          <el-input v-model="form.minWithdrawBalance" placeholder="请输入余额最低提现金额"/>
        </el-form-item>
        <el-form-item label="奖励金最低提现金额" prop="minWithdrawBonus">
          <el-input v-model="form.minWithdrawBonus" placeholder="请输入奖励金最低提现金额"/>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listWallet_order, getWallet_order, delWallet_order, addWallet_order, updateWallet_order, exportWallet_order} from "@/api/wallet/wallet_order";

export default {
  name: "Wallet_order",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 日期范围
      dateRange: [],
      // 钱包订单表格数据
      wallet_orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 订单类型字典
      orderTypeOptions: [],
      // 钱包类型字典
      walletTypeOptions: [],
      // 订单状态字典
      orderStatusOptions: [],
      // 状态字典
      stateOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNo: null,
        walletNo: null,
        custNo: null,
        orderType: null,
        applyAmount: null,
        amount: null,
        serviceFee: null,
        walletType: null,
        bankCode: null,
        bankAccount: null,
        fromWhere: null,
        toDest: null,
        batchSerialNo: null,
        loanSerialNo: null,
        orderStatus: null,
        serviceRate: null,
        minWithdrawBalance: null,
        minWithdrawBonus: null,
        state: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        serialNo: [
          {required: true, message: "订单流水号不能为空", trigger: "blur"}
        ],
        walletNo: [
          {required: true, message: "钱包账户号不能为空", trigger: "blur"}
        ],
        custNo: [
          {required: true, message: "客户号不能为空", trigger: "blur"}
        ],
        orderType: [
          {required: true, message: "订单类型不能为空", trigger: "change"}
        ],
        amount: [
          {required: true, message: "订单金额不能为空", trigger: "blur"}
        ],
        walletType: [
          {required: true, message: "钱包类型不能为空", trigger: "change"}
        ],
        state: [
          {required: true, message: "状态不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("wallet_order_type").then(response => {
      this.orderTypeOptions = response.data;
    });
    this.getDicts("wallet_type").then(response => {
      this.walletTypeOptions = response.data;
    });
    this.getDicts("wallet_order_status").then(response => {
      this.orderStatusOptions = response.data;
    });
    this.getDicts("state").then(response => {
      this.stateOptions = response.data;
    });
  },
  methods: {
    /** 查询钱包订单列表 */
    getList() {
      this.loading = true;
      listWallet_order(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.wallet_orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 订单类型字典翻译
    orderTypeFormat(row, column) {
      return this.selectDictLabel(this.orderTypeOptions, row.orderType);
    },
    // 钱包类型字典翻译
    walletTypeFormat(row, column) {
      return this.selectDictLabel(this.walletTypeOptions, row.walletType);
    },
    // 订单状态字典翻译
    orderStatusFormat(row, column) {
      return this.selectDictLabel(this.orderStatusOptions, row.orderStatus);
    },
    // 状态字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serialNo: null,
        walletNo: null,
        custNo: null,
        orderType: null,
        applyAmount: null,
        amount: null,
        serviceFee: null,
        walletType: null,
        bankCode: null,
        bankAccount: null,
        fromWhere: null,
        toDest: null,
        batchSerialNo: null,
        loanSerialNo: null,
        orderStatus: null,
        serviceRate: null,
        minWithdrawBalance: null,
        minWithdrawBonus: null,
        state: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        dateRange: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.dateRange = [];
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加钱包订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWallet_order(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改钱包订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWallet_order(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWallet_order(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除钱包订单编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delWallet_order(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有钱包订单数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportWallet_order(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
